package com.gxa.saas.portal.controller.hhy;

import com.gxa.saas.core.entity.vo.hhy.MonthVO;
import com.gxa.saas.core.entity.vo.hhy.PercentVO;
import com.gxa.saas.core.entity.vo.hhy.UserInfoVO;
import com.gxa.saas.core.utils.JwtUtil;
import com.gxa.saas.portal.service.hhyservice.SelectShopIdService;
import com.gxa.saas.portal.service.hhyservice.ShopUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags="用户管理相关接口")
@RestController
@RequestMapping("/shopUser")
@Validated

public class ShopUserController {

    @Autowired
    private ShopUserService shopUserService;

    @Autowired
    private SelectShopIdService selectShopIdService;

    @ApiOperation("新用户")
    @GetMapping("/newUser")
    public Map newUser(HttpServletRequest request){

        String loginId = JwtUtil.getUsername(request.getAttribute("token1").toString());
        Integer shopid =this.selectShopIdService.getShopId(loginId);

        List<MonthVO> list = shopUserService.getNewUser(shopid);

        Map map = new HashMap();
        map.put("code", 200);
        map.put("msg", "当月新增用户信息");
        map.put("data",list);
        return map;
    }

    @ApiOperation("访问量")
    @GetMapping("/totalVisit")
    public Map totalVisit(HttpServletRequest request){
        String loginId = JwtUtil.getUsername(request.getAttribute("token1").toString());
        Integer shopid =this.selectShopIdService.getShopId(loginId);

        List<MonthVO> list = shopUserService.getTotalVisit(shopid);

        Map map = new HashMap();
        map.put("code", 200);
        map.put("msg", "当月总访问信息");
        map.put("data",list);
        return map;
    }

    @ApiOperation("订单量")
    @GetMapping("/allOrder")
    public Map allOrder(HttpServletRequest request){
        String loginId = JwtUtil.getUsername(request.getAttribute("token1").toString());
        Integer shopid =this.selectShopIdService.getShopId(loginId);

        List<MonthVO> list = shopUserService.getAllOrder(shopid);

        Map map = new HashMap();
        map.put("code", 200);
        map.put("msg", "当月总订单信息");
        map.put("data",list);
        return map;
    }

    @ApiOperation("用户信息")
    @GetMapping("/userInfo")
    public Map userInfo(HttpServletRequest request){
        String loginId = JwtUtil.getUsername(request.getAttribute("token1").toString());
        Integer shopid =this.selectShopIdService.getShopId(loginId);

        List<UserInfoVO> list = shopUserService.getUserInfo(shopid);

        Map map = new HashMap();
        map.put("code", 200);
        map.put("msg", "用户信息");
        map.put("data",list);
        return map;
    }

/*    @PostMapping("/shopuser")
    public Map deletShopUser(Integer id){
        System.out.println(id);

        Map map = new HashMap();
        map.put("code", 200);
        map.put("msg", "用户id");
        return map;
    }*/

}
